package com.ebeijia.service.admin.impl;

import com.ebeijia.mybatis.mapper.BillPushInfoMapper;
import com.ebeijia.mybatis.mapper.UserInfoMapper;
import com.ebeijia.mybatis.pojo.BillPushInfo;
import com.ebeijia.mybatis.pojo.UserInfo;
import com.ebeijia.service.admin.BillPushInfoService;
import com.ebeijia.util.LoggerUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by YPJ on 2016/5/23.
 */
@Service
public class BillPushInfoServiceImpl implements BillPushInfoService {
    @Resource
    private UserInfoMapper userInfoMapper;
    @Resource
    private BillPushInfoMapper billPushInfoMapper;
    @Override
    public int insertBatch(String status, List<String> userNos) {
        List<BillPushInfo> billPushInfos = new ArrayList<>();
        Date now = new Date();
        for (String userNo : userNos) {
          List<UserInfo> userInfos =  userInfoMapper.selectByPrimaryUserNo(userNo);
            for(UserInfo userInfo:userInfos){
                BillPushInfo billPushInfo = new BillPushInfo();
                billPushInfo.setBillDate(now);
                billPushInfo.setBillStatus("01");
                billPushInfo.setUserNo(userNo);
                billPushInfo.setOpenId(userInfo.getOpenId());
                billPushInfos.add(billPushInfo);
            }

        }
        return billPushInfoMapper.insertBatch(billPushInfos);
    }

    @Override
    public int deleteBatch(List<String> userNos) {
        return billPushInfoMapper.deleteBatch(userNos);
    }

    @Override
    public List<BillPushInfo> selectByAll() {
        return billPushInfoMapper.selectByAll();
    }

    @Override
    public Map<String, Object> callPushInfo(Map<String, Object> map) {
        return billPushInfoMapper.callPushInfo(map);
    }
}
